<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file="common/head" /}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form action="" id="form" class="layui-form" method="post">
            <input type="hidden" name="ad_id" value="{$info.ad_id|default=0}">

            <div class="layui-form-item">
                <label for="pid" class="layui-form-label">
                    <span class="x-red">*</span>广告位置
                </label>
                <div class="layui-input-inline">
                    <select id="pid" name="pid" lay-filter="pid" required=""
                            lay-verify="required">
                        <option value="">请选择广告位置</option>

                        {volist name="position" id="vo"}
                        <option value="{$vo.position_id}">{$vo.position_name}</option>
                        {/volist}
                    </select>
                    <script>$("#pid option[value = '{$info.pid}']").attr("selected","selected");</script>
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="ad_name" class="layui-form-label">
                    <span class="x-red">*</span>广告名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.ad_name}" id="ad_name" name="ad_name" required=""
                           lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="ad_link" class="layui-form-label">
                    <span class="x-red"></span>广告链接
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.ad_link|default=''}" id="ad_link" name="ad_link" autocomplete="off" class="layui-input" placeholder="http://">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="photo" class="layui-form-label">
                    <span class="x-red">*</span>广告图片
                </label>
                <div class="layui-input-inline">
                    <div class="public-img-box">
                        <img src="{$info.thumb|default='/static/admin/images/img.png'}" id="photo_url" style="width: 120px; height: 120px" alt="">
                    </div>
                    <button type="button" class="layui-btn" id="photo">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <input type="hidden" name="thumb" id="photo_input" value="{$info.thumb}" required=""
                           lay-verify="required" />
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="start_time" class="layui-form-label">
                    <span class="x-red"></span>投放时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info['start_time']?date('Y-m-d',$info['start_time']):''}" id="start_time" name="start_time" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="end_time" class="layui-form-label">
                    <span class="x-red"></span>结束时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info['end_time']?date('Y-m-d',$info['end_time']):''}" id="end_time" name="end_time" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="bgcolor" class="layui-form-label">
                    <span class="x-red"></span>背景颜色
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.bgcolor}" id="bgcolor" name="bgcolor" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    (如：#ffffff)
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red"></span>状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" {eq name="info['status']" value="1" }checked{/eq}
                    lay-skin="primary" title="正常" checked="">
                    <input type="radio" name="status" value="0" {eq name="info['status']" value="0" }checked{/eq}
                    lay-skin="primary" title="禁用">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="ok" class="layui-form-label">
                </label>
                <button id="ok" class="layui-btn" lay-filter="add" lay-submit="">
                    {empty name="info['ad_id']"}
                    增 加
                    {else /}
                    修 改
                    {/empty}

                </button>
            </div>
        </form>
    </div>
</div>

<div id="idbox" style="display: none">

</div>
<script>
    layui.use(['form', 'layer','laydate'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        var laydate = layui.laydate;

        //自定义验证规则
        form.verify({

        });

        layui.use('upload', function(){
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#photo' //绑定元素
                ,url: '{:url("File/upload")}' //上传接口
                ,accept: 'images' //只允许上传图片
                ,acceptMime: 'image/*' //只筛选图片
                ,before: function(obj){
                    layer.load();
                }
                ,done: function(res){
                    if(res.code){
                        $("#photo_url").attr("src",res.data.url);
                        $("#photo_input").val(res.data.url);
                    }else{
                        layer.msg(res.msg,{icon:2,time:1000});
                    }
                    layer.closeAll('loading');
                }
                ,error: function(res){
                    //请求异常回调
                    layer.closeAll('loading');
                }
            });
        });

        laydate.render({
            elem: '#start_time'
        });
        laydate.render({
            elem: '#end_time'
        });

        //监听提交
        form.on('submit(add)',
            function (data) {
                $.ajax({
                    type: "POST",
                    url: "{:url()}",
                    data: data.field,
                    success: function (result) {
                        layer.alert(result.msg, {
                            icon: 6
                        }, function () {
                            xadmin.close();
                            xadmin.father_reload();
                        });
                    },
                    error: function (data) {
                        layer.alert(result.msg, {
                            icon: 2
                        }, function () {
                            xadmin.close();
                        });
                    }

                });
                return false;
            });

        $("#idbox").load("/static/admin/icon.html");
        var html = "";
        $("#showIcon").click(function () {
            if (html == "") {
                html = $("#idbox").html();
                $("#idbox").html("")
            }

            layer.open({
                type: 1,
                shadeClose: true,
                skin: 'layui-layer-rim', //加上边框
                area: ['800px', '100%'], //宽高
                content: html
            });
        });


    });
</script>

</body>

</html>
